/**把数字转换为有两位小数的数字
 * 例如
 * 1 --> 1.00
 * 1.1 --> 1.10
 * 1.11 --> 1.11
 */

const numberToFixed2 = (num) => {
    num = num.toString();
    if (num.includes(".")) {
        let _num = num.split(".");
        let num0 = _num[0];
        let num1 = _num[1];
        if (num1.length < 2) {
            return num0 + "." + num1.padEnd(2, "0");
        } else if (num1.length === 2) {
            return num;
        } else {
            return num0 + "." + num1.slice(0, 2); // 不做四舍五入 直接截取
        }
    } else {
        return num + ".00";
    }
};

export default numberToFixed2;
